package com.example.mapper;

import com.example.entity.Bed;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 操作Bed相关数据接口
*/
public interface BedMapper {

    /**
      * 新增
    */
    int insert(Bed Bed);

    /**
      * 删除
    */
    int deleteById(Integer id);

    /**
      * 修改
    */
    int updateById(Bed Bed);

    /**
      * 根据ID查询
    */
    Bed selectById(Integer id);

    /**
      * 查询所有
    */
    List<Bed> selectAll(Bed Bed);

    /**
     * 根据科室的departmentname实现查看自己的预约
     * @paramdepartment_id
     * @return
     */
//    @Select("select patients.name, department.name, visit_date_time, status, created_time\n" +
//            "from Bed,department,patients \n" +
//            "where patients.username = Bed.patient_id and department.username = Bed.department_id \n" +
//            "and department_id = #{department_id}")
//    @Select("select patients.name as patientName,\n" +
//            "department.name as departmentName,\n" +
//            "Bed.id, department_id, patient_id, visitDate, status, outDate\n" +
//            "from Bed,department,patients \n" +
//            "where patients.id = Bed.patient_id and department.id = Bed.department_id \n" +
//            "and department_id = #{department_id} ")
//    List<Bed> selectByDepartmentName(String departmentName);

    @Select("SELECT patients.name AS patientName, " +
            "department.name AS departmentName, " +
            "Bed.id, Bed.department_id, Bed.patient_id, Bed.visit_date, Bed.status, Bed.out_date " +
            "FROM Bed " +
            "LEFT JOIN patients ON patients.id = Bed.patient_id " +
            "LEFT JOIN department ON department.id = Bed.department_id " +
            "WHERE Bed.department_id = #{departmentId}")
    List<Bed> selectByDepartmentName(@Param("departmentName") String departmentName);

    @Select("SELECT * FROM Bed WHERE bed_id = #{bedId}")
    Bed selectByBedId(String bedId);

}